package com.vecspace.middleplatform.filemanagment.httphandler;
import java.util.ArrayList;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;

import com.vecspace.data.model.FilterColumn;
import com.vecspace.database.model.QueryResult;
import com.vecspace.middleplatform.filemanagment.pojo.UploadFileStorage;
import com.vecspace.middleplatform.filemanagment.service.UploadFileStorageService;
import com.vecspace.web.servlet.model.BaseController;
import com.vecspace.web.servlet.model.FtlViewModel;
import com.vecspace.web.servlet.model.HttpHandler;
import com.vecspace.web.servlet.model.Param;
import com.vecspace.web.servlet.model.Path;
import com.vecspace.web.servlet.model.ViewModel;

/** 文件存储路径 httphandler
 * 在handler中进行与页面相关的处理，比如把数据转换为HTML格式等。
 * @reviewer
 * @template wanghua
 * @version 1.0
*/
@HttpHandler
public class UploadFileStorageHandler extends BaseController {

	/**根据ID查询 文件存储路径
	 * @return UploadFileStorage
	 * @throws Exception
	 * @reviewer 
	 */
	@Path("getUploadFileStorage")
	public UploadFileStorage getUploadFileStorage(@Param("id") String id) throws Exception {
		return uploadFileStorageService.getUploadFileStorage(id);
	}

	/** 插入或修改 文件存储路径 
	 * @param item	要保存的对象
	 * @return void
	 * @throws Exception
	 * @reviewer
	 */
	@Path("saveUploadFileStorage")
	public UploadFileStorage saveUploadFileStorage(@Param("item") UploadFileStorage item) throws Exception {
		if (item == null){
			return null;
		}
		/*** 对item对象进行校验，如必填项，格式，逻辑关系等 ***/
		//String loginId = LoginManager.getLoginUserId();
		String loginId = null;
		return uploadFileStorageService.saveViewUploadFileStorage(item, loginId);
	}

	/** 根据ID删除 文件存储路径 
	 * @param id	主键值
	 * @return void
	 * @throws Exception
	 * @reviewer
	 */
	@Path("deleteUploadFileStorage")
	public void deleteUploadFileStorage(@Param("id") String id) throws Exception {
		uploadFileStorageService.deleteUploadFileStorage(id);
	}

	/**
	 * 根据多个查询条件执行分页查询 
	 * 
	 * @param queryFields	查询条件
	 * @param pageIndex	  页数 从1开始
	 * @param pageSize	   每页显示的数据条数
	 * @param sortField	  排序字段
	 * @param sortOrder	  排序方式 asc desc
	 * @return PageModel
	 * @throws Exception
	 * @reviewer
	 */
	@Path("getUploadFileStorageExList")
	public QueryResult<UploadFileStorage> getUploadFileStorageExList(@Param("queryFields") ArrayList<FilterColumn> queryFields,
			@Param("page") int page, @Param("limit") int pageSize, @Param("sortname") String sortname, @Param("sortorder") String sortorder) throws Exception {
		return uploadFileStorageService.getUploadFileStorageExList(queryFields, page, pageSize, sortname, sortorder);
	}

	/************** Page View *************************/
	/**跳转到信息显示页面，id为空，则表示新增记录
	 * @param id UploadFileStorage.id
	 * @return ViewModel
	 * @throws Exception
	 * @reviewer
	 */
	@Path(value="info", httpGet=true)
	public ViewModel info(@Param("id") String id)  throws Exception {
		Map<String, Object> params = this.getRequestParameters();
		return new FtlViewModel("view/vecspace/middleplatform/filemanagementpart/uploadFileStorage/uploadFileStorage_info.ftl", params);
	}

	@Path(value="add", httpGet=true)
	public ViewModel add() throws Exception {
		return edit(null);
	}

	/**跳转到信息编辑页面，id为空，则表示新增记录
	 * @param id UploadFileStorage.id
	 * @return ViewModel
	 * @throws Exception
	 * @reviewer
	 */
	@Path(value="edit", httpGet=true)
	public ViewModel edit(@Param("id") String id) throws Exception {
		Map<String, Object> params = this.getRequestParameters();
		params.put("id", id);

		return new FtlViewModel("view/vecspace/middleplatform/filemanagementpart/uploadFileStorage/uploadFileStorage_edit.ftl", params);
	}

	/**跳转到信息列表页面
	 * @return ViewModel
	 * @throws Exception
	 * @reviewer
	 */
	@Path(value="list", httpGet=true)
	public ViewModel list() throws Exception {
		Map<String, Object> params = this.getRequestParameters();
		return new FtlViewModel("view/vecspace/middleplatform/filemanagementpart/uploadFileStorage/uploadFileStorage_list.ftl", params);
	}

	/************* property ********************/
	@Autowired
	private UploadFileStorageService uploadFileStorageService;
	public UploadFileStorageService getUploadFileStorageService() {
		return uploadFileStorageService;
	}
	public void setUploadFileStorageService(UploadFileStorageService uploadFileStorageService) {
		this.uploadFileStorageService = uploadFileStorageService;
	}

}
